﻿using HybridLab.Virtual.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HybridLab.Workflow.Activities.Info
{
	[Serializable]
	public class HybridLabEnvironmentSnapshotInfo
	{
		public List<HybridLabVMSnapshotInfo> Snapshots { get; set; }

		public HybridLabEnvironmentSnapshotInfo()
		{
			Snapshots = new List<HybridLabVMSnapshotInfo>();
		}

		public void Clear()
		{
			Snapshots.Clear();
		}

		public void AddMachineSnapshot(string machineName, string snapshotName)
		{
			var snap = Snapshots.FirstOrDefault(s => s.MachineName == machineName);
			if (snap != null)
			{
				snap.SnapshotName = snapshotName;
			}
			else
			{
				Snapshots.Add(new HybridLabVMSnapshotInfo() { MachineName = machineName, SnapshotName = snapshotName });
			}
		}

		public void SetAllToSameSnapshotName(IVirtualHost host, string commonName)
		{
			host.GetVMs().ForEach(vm =>
				{
					Snapshots.Add(new HybridLabVMSnapshotInfo() { MachineName = vm.Name, SnapshotName = commonName });
				});
		}
	}
}
